unit UTrocaEmpresaTitulo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, DB, DBCtrls, DBTables;

type
  TFTrocaEmpresaTitulo = class(TForm)
    Label1: TLabel;
    DBLEmpresa: TDBLookupComboBox;
    DsEmpresa: TDataSource;
    BitTrocar: TBitBtn;
    BitFechar: TBitBtn;
    QExec: TQuery;
    procedure BitTrocarClick(Sender: TObject);
    procedure BitFecharClick(Sender: TObject);
  private
    { Private declarations }
  public
    Tabela : String;
    CP_CR  : String;
    Titulo : String;
    { Public declarations }
  end;

var
  FTrocaEmpresaTitulo: TFTrocaEmpresaTitulo;

implementation

uses UDMGeral, UDmGestao, ContasPagar, ContasReceber;

{$R *.dfm}

procedure TFTrocaEmpresaTitulo.BitTrocarClick(Sender: TObject);
const Trocar = ' UPDATE CONTAS%s SET CODIGOEMPRESA = %s WHERE %s_CODIGO = %s ';
begin

  QExec.Close;
  QExec.SQL.Clear;
  QExec.SQL.Add(Format(Trocar,[Tabela,
                               VartoStr(DBLEmpresa.KeyValue),
                               CP_CR,
                               Titulo]));
  QExec.ExecSQL;

  if CP_CR = 'CP' then
    FContasPagar.Trocar := True
  else
    FContasReceber.Trocar := True;

  close;

end;

procedure TFTrocaEmpresaTitulo.BitFecharClick(Sender: TObject);
begin
  if CP_CR = 'CP' then
    FContasPagar.Trocar := False
  else
    FContasReceber.Trocar := False;
end;

end.
